package org.shj.sso.util;

import java.io.InputStream;
import java.util.Properties;

/**
 * @author Shen Huang Jian
 * @date 2019/7/2
 */
public class PropertyUtil {

    private static Properties properties;

    private static volatile boolean init = false;

    private static Object lock = new Object();

    public static String get(String key){
        return getProperties().getProperty(key);
    }

    private static Properties getProperties(){
        if(!init){
            synchronized (lock){
                if(!init){
                    InputStream inputStream = Thread.currentThread().getContextClassLoader()
                            .getResourceAsStream("conf.properties");
                    properties = new Properties();
                    try {
                        properties.load(inputStream);
                        init = true;
                    }catch (Exception e){
                        e.printStackTrace();
                    }
                }
            }
        }
        return properties;
    }
}
